import axios from 'axios';
import NProgress from "nprogress";

import {
  TIMEOUT
} from "./config";

axios.defaults.withCredentials = true;

const instance = axios.create({
  timeout: TIMEOUT
})

// 请求拦截
instance.interceptors.request.use(config => {
  NProgress.start();
  return config;
}, err => {
  NProgress.done();
  return err;
})

// 响应拦截
instance.interceptors.response.use(response => {
  NProgress.done();
  return response.data;
}, err => {
  NProgress.done();
  console.log(err)
})

export default instance;
